//
//  ByDefaultImageView.m
//  caipiao_ios
//
//  Created by mc on 2018/10/24.
//  Copyright © 2018年 ZhangZhanbin. All rights reserved.
//

#import "ByDefaultImageView.h"

@implementation ByDefaultImageView



- (id)initWithFrame:(CGRect)frame WithName:(NSString *)imageName WithSize:(CGSize )Size{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = rgba(238, 238, 238, 1);
        UIImageView *defaultView = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width - Size.width) / 2.0, (frame.size.height - Size.height) / 2.0, Size.width, Size.height)];
        [self addSubview:defaultView];
        defaultView.image = [UIImage imageNamed:imageName];
    }
    return self;
}

+ (UIImage*)createImageFromView:(UIView*)view{
    // 创建一个bitmap的context
    // 并把它设置成为当前正在使用的context
    UIGraphicsBeginImageContext(view.bounds.size);
    CGContextRef currnetContext = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:currnetContext];
    // 从当前context中创建一个改变大小后的图片
    UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
    // 使当前的context出堆栈
    UIGraphicsEndImageContext();
    return image;
}





@end
